package pl.edu.pw.perg.compinfodb.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;

import pl.edu.pw.perg.compinfodb.entities.ElementType;

public class ElementTypeDAO extends GenericSpringDAO<ElementType> implements
		IElementTypeDAO {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * pl.edu.pw.perg.compinfodb.dao.IElementTypeDAO#findTypes(java.lang.String,
	 * java.lang.Object)
	 */
	@Override
	public void deleteAll() {
		Session s = getSession();
		Query q = s.createQuery("delete from ElementType");
		q.executeUpdate();
	}

	public List<ElementType> findRoots() {
		return findByCriteria(Expression.isNull("parentType"));
	}

	public List<ElementType> findRootCables() {
		return findByCriteria(Expression.conjunction().add(Expression.isNull("parentType")).add(Expression.eq("cable", true)));
	}

	public List<ElementType> findRootModules() {
		return findByCriteria(Expression.conjunction().add(Expression.isNull("parentType")).add(Expression.eq("cable", false)));
	}

}
